const WITHDRAW_STATUS = {
  'problems': '有问题',
  'suspicious': '可疑',
  'cancelled': '已取消',
  'scheduled': '延时提现',
  'rejected': '被拒绝',
  'pending': '等待中',
  'accepted': '已通知渠道',
  'retrieved': '已接收'
}
const WITHDRAW_STATUS_COLOR = {
  'problems': 'danger',
  'cancelled': 'info',
  'rejected': 'info',
  'pending': 'warning',
  'accepted': 'info',
  'retrieved': 'success',
  'suspicious': 'danger'
}

const PAYMENT = {
  'huifu': '汇付',
  'fuiou': '富友'
}

export default {
  Withdraw: {
    list: {
      // 额外component异步获取的数据如果需要导出，要独立界面和导出方法
      export: {
        query: {
          '@display': `{
          'id' : 'entity.getId()',
          'user' : 'entity.getUser().getUsername()',
          'batchNo' : 'entity.getBatchNo()',
          'amount' : 'entity.getAmount()',
          'fee',
          'status' : '{ "problems": "有问题", "cancelled": "已取消", "rejected": "被拒绝", "pending": "等待中", "accepted": "已通过", "retrieved": "已接收" }[entity.getStatus()]',
          'createdTime' : 'entity.getCreatedTime().format("Y-m-d H:i:s")',
          'payment' : 'entity.getPayment()'
        }`,
          limit: 10000000
        },
        label: {
          'id': 'id',
          'user': '用户',
          'batchNo': '批号',
          'amount': '金额',
          'fee': '手续费',
          'status': '状态',
          'createdTime': '创建时间',
          'payment': '提现渠道'
        }
      },
      disabled_actions: ['new', 'delete'],
      query: {
        '@order': 'entity.id|DESC'
      },
      list_filter: {
        'user.username': '电话',
        status: Object.assign({ __label: '状态' }, WITHDRAW_STATUS),
        beforeCreatedTime: {
          expression: 'entity.getCreatedTime() >= datetime.get(":value  00:00:00")',
          label: '开始时间',
          type: 'date'
        },
        afterCreatedTime: {
          expression: 'entity.getCreatedTime() < datetime.get(":value 23:59:59")',
          label: '结束时间',
          type: 'date'
        },
        hadPay: {
          expression: 'entity.getFee() == :value',
          label: '快速提现',
          type: 'input'
        }
      },
      list_display: [
        'id',
        'user',
        {
          property: 'user',
          label: '汇付账号',
          component: {
            props: ['data'],
            data() {
              return {
                name: '无绑定'
              }
            },
            created() {
              this.axios.get(`/manage/huifu-accounts`, { params: { '@filter': `entity.getUser().getId() == ${this.data.id}` } }).then((res) => {
                if (res.data.length > 0) {
                  this.name = '汇付:' + res.data[0].cardInfo.card_name + `(${res.data[0].store.__toString})`
                }
              })
            },
            render(h) {
              return <div style='width:220px'>{this.name}</div>
            }
          }
        },
        'batchNo',
        'amount',
        { property: 'fee', label: '手续费' },
        {
          property: 'status',
          component: {
            props: ['data'],
            data() {
              return {
                status: WITHDRAW_STATUS,
                color: WITHDRAW_STATUS_COLOR
              }
            },
            render(h) {
              return <el-tag type={this.color[this.data]} effect='plain' onclick={() => {
                console.log(this.data)
                if (this.data === 'problems') {
                  console.log('可以取消')
                  this.axios.post(`/manage/huifu-accounts/accpayment/refund`,{
                    org_req_date: '20240625',
                    org_req_seq_id: '326593800505982976',
                    ord_amt: 1
                  }).then((res) => {
                    this.$message.success('回退成功！')
                  })
                } else {
                  console.log('不能取消')
                }
              }}>{this.status[this.data]}</el-tag>
            }
          }
        },
        'createdTime',
        'lastModifiedTime',
        {
          property: 'payment',
          label: '提现渠道',
          component: {
            props: ['data'],
            render(h) {
              return <div>{PAYMENT[this.data]}</div>
            }
          }
        }
      ]
    },
    form: {
      fields: [
        'payment'
      ]
    }
  }
}

